package utils

import (
	"github.com/gin-gonic/gin"
	"xinduobang/stock/common"
	"xinduobang/stock/core/log"
)

func Print(c *gin.Context, fields ...interface{}) {
	log.Print(AddArgs(c, fields...)...)
}
func Printf(c *gin.Context, template string, args ...interface{}) {
	log.Printf(" %s "+template, AddArgs(c, args...)...)
}

func Debug(c *gin.Context, fields ...interface{}) {
	log.Debug(AddArgs(c, fields...)...)
}
func Debugf(c *gin.Context, template string, args ...interface{}) {
	log.Debugf(" %s "+template, AddArgs(c, args...)...)
}

func Info(c *gin.Context, fields ...interface{}) {
	log.Info(AddArgs(c, fields...)...)
}
func Infof(c *gin.Context, template string, args ...interface{}) {
	log.Infof(" %s "+template, AddArgs(c, args...)...)
}

func Error(c *gin.Context, fields ...interface{}) {
	log.Error(AddArgs(c, fields...)...)
}
func Errorf(c *gin.Context, template string, args ...interface{}) {
	log.Errorf(" %s "+template, AddArgs(c, args...)...)
}

func Fatal(c *gin.Context, fields ...interface{}) {
	log.Fatal(AddArgs(c, fields...)...)
}
func Fatalf(c *gin.Context, template string, args ...interface{}) {
	log.Fatalf(" %s "+template, AddArgs(c, args...)...)
}

func Panic(c *gin.Context, fields ...interface{}) {
	log.Panic(AddArgs(c, fields...)...)
}
func Panicf(c *gin.Context, template string, args ...interface{}) {
	log.Panicf(" %s "+template, AddArgs(c, args...)...)
}

func GetTraceId(c *gin.Context) string {
	if c == nil {
		log.Error("error:", "c is nil")
		return ""
	}

	traceId := c.GetString(common.TRACE_ID) + " "
	return traceId
}

//
//func GetTraceId2(c context.Context) string {
//	//c.Value()
//}

func AddArgsWithTraceId(c *gin.Context, args ...interface{}) []interface{} {
	return append([]interface{}{"traceId: " + GetTraceId(c) + " "}, args...)
}

func AddArgs(c *gin.Context, args ...interface{}) []interface{} {
	return append([]interface{}{GetTraceId(c)}, args...)
}
